/*
 * Created on 2005-6-22
 *
 * 
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.dcivision.dms.web;

import java.sql.Connection;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.dcivision.dms.bean.DmsDefaultProfileSetting;
import com.dcivision.dms.core.DocumentRetrievalManager;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.web.AbstractActionForm;
import com.dcivision.framework.web.AbstractMaintAction;

/**
 * @author Administrator
 *
 * 
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class MaintDmsDisplaySeqAction extends AbstractMaintAction{
  public static final String REVISION = "$Revision: 1.2.2.1 $";
  
  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException {
  	MaintDmsDisplaySeqForm actionForm = (MaintDmsDisplaySeqForm) form;
	SessionContainer sessionContainer = this.getSessionContainer(request);
	Connection conn = this.getConnection(request); 
	
//	Create Fields for the defined type of User Defined Index
    //request.setAttribute("listSize", new Integer(request.getParameter("listSize")));
    //int listSize = new Integer(request.getParameter("listSize")).intValue();
    //int custValidateCount = this.custValidateCount(mapping, actionForm, request, response)-1;
    
	    
	return mapping.findForward(GlobalConstant.NAV_MODE_EDIT); 
	}

    public String getFunctionCode() {
      return null;
    }

    public String getMajorDAOClassName() {
     return null;
    }
    
    public int custValidateCount(ActionMapping mapping, AbstractActionForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException{
      	int count = 0;
      	boolean flag =false;
      	
      	SessionContainer sessionContainer = this.getSessionContainer(request);
        Connection conn = this.getConnection(request);
        DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer,conn);
        
        List defaultProfileField = docRetrievalManager.checkNSetDefaultProfileList(request);    
        
        int listSize = new Integer(request.getParameter("listSize")).intValue();
        
        for (int i = 0; i < listSize; i++) {    	
          count = count+1;
          String definedField= new String(request.getParameter("definedField_" + i));
          String definedFieldLowerCase =(new String(request.getParameter("definedField_" + i))).toLowerCase();
          for(int j=0;j<defaultProfileField.size();j++){
            DmsDefaultProfileSetting dmsDefaultProfileSetting = (DmsDefaultProfileSetting)defaultProfileField.get(j);      
            if("name".equals(definedFieldLowerCase)||"reference no".equals(definedFieldLowerCase)||"description".equals(definedFieldLowerCase)||dmsDefaultProfileSetting.getFieldName().equals(definedField)){
              flag =true;
              break;
            }
          }
          if(flag){
          	break;
          }
        }
        return count;
      }

}
